package org.reenscape.lib;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
/**
* Loads configuration from XML file.
@author Jim
@version 1.0
*/
public class Configuration {

		/**
		* Loads the config from the XML file.
		*/
		public static void LoadConfig() throws IOException {
			Properties props = new Properties();
			props.loadFromXML(new FileInputStream("../local/Config.xml"));
			
			basePort = Integer.parseInt(props.getProperty("port"));
			log = Boolean.parseBoolean(props.getProperty("log"));
			debug = Boolean.parseBoolean(props.getProperty("debug"));
			WorldID = Integer.parseInt(props.getProperty("world"));
			int sqlid = Integer.parseInt(props.getProperty("sqlnum"));
			MySQLUsername = props.getProperty("sqlusername"+sqlid);
			MySQLPassword = props.getProperty("sqlpassword"+sqlid);
			MySQLAddress = props.getProperty("sqladdress"+sqlid);
			MySQLDatabase = props.getProperty("sqldatabase"+sqlid);
			MySQLPort = Integer.parseInt(props.getProperty("sqlport"+sqlid));
		}
		
		static {
			try {
				LoadConfig();
			} catch(Exception e) {System.out.println("Failed loading config!");}
		}
		
		/**
		* Base port used for listeners.
		*/
		public static int basePort;
		
		/**
		* Flags logging on or off.
		*/
		public static boolean log;
		
		/**
		* Flags debugging on or off.
		*/
		public static boolean debug;
		
		/**
		* World ID number. World x.
		*/
		public static int WorldID;
		
		/**
		* SQL username
		*/
		public static String MySQLUsername = null;
		
		/**
		* SQL password
		*/
		public static String MySQLPassword = null;
		
		/**
		* SQL address
		*/
		public static String MySQLAddress = null;
		
		/**
		* SQL database name
		*/
		public static String MySQLDatabase = null;
		
		/**
		* SQL port
		*/
		public static int MySQLPort = 3306;
}